﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;

namespace Core.Library
{
    public class CacheHelper
    {

        #region CacheKey
        public class CacheKey
        {

            public static string GetCacheKey(string functionName, params object[] listParams)
            {
                return Const.PREFIX_CACHE + functionName + "_" + string.Join("_", listParams);
            }

            //public static string GetCacheKey(string functionName, IEnumerable<object> listParams)
            //{

            //    return functionName + "_" + CalculateInvocationHash(listParams);
            //}

            //private static long CalculateInvocationHash(IEnumerable<object> listParams)
            //{
            //    return listParams == null ? 0 : listParams.Aggregate(0, (accum, current) =>
            //        accum * 31 +
            //            (
            //                current == null ? 0 :
            //                (
            //                    current is Array ? (int)CalculateInvocationHash(((IEnumerable)current).Cast<object>()) : current.GetHashCode()
            //                )
            //            )
            //        );
            //}

            //private static IEnumerable<object> CastToObjects(Array arr)
            //{

            //    if (arr != null && arr.Length > 0)
            //    {
            //        List<object> l = new List<object>();
            //        foreach (var item in arr)
            //        {
            //            l.Add(item);
            //        }
            //        return l as IEnumerable<object>;
            //    }
            //    return null;
            //}


        }



        #endregion
    }
}
